package com.marketingexpert.controller.streammgnt;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.domain.Tab;
import com.marketingexpert.service.streammgnt.StreamService;

public class GetAllTabController implements Controller {

	private StreamService streamService = null;
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/x-json;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		
		String parentUserId = (String) request.getSession().getAttribute("parentUserId");
		
		List<Tab> tabs = getStreamService().queryTabByUserId(parentUserId); 
		
		PrintWriter out = response.getWriter(); 
		JSONArray jsonListd = JSONArray.fromObject(tabs); 
		out.print(jsonListd);
		return null;
	}

	public StreamService getStreamService() {
		return streamService;
	}

	public void setStreamService(StreamService streamService) {
		this.streamService = streamService;
	}
	
	

}
